/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sql_client;

/**
 *
 * @author hauhaulovely
 */
public class SQL_Client {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
        //cau query
        String query = "select sv,hoten,namsinh from Sv sv,GV gv where MSSV = '1'";
        query.toLowerCase();
        //chon command
        String command[] = {"select", "insert", "delete", "update","create database", "create table"};
        String choose = null;
        for(int i = 0; i < command.length; i++)
        {
            if(query.indexOf(command[i], 0) != -1)
            {
                choose = command[i];
            }
        }
        //xu ly command
        switch(choose)
        {
            case "select":
            {
                String selectAnalyze = query.substring(6,query.length());
                //select
                String stringSelect[] = selectAnalyze.split("from");
                String Select[] = stringSelect[0].split(",");
                for(int i = 0; i < Select.length; i++)
                {
                    Select[i].trim();
                }
                //from
                String fromAnalyze = query.substring(("select" + stringSelect[0]+"from").length(),query.length());
                System.out.println(fromAnalyze);
                String stringFrom[] = fromAnalyze.split("where");
                String From[] = stringFrom[0].split(",");
                for(int i = 0; i < From.length; i++)
                {
                    System.out.println(From[i].trim());
                }
                //where
                String whereAnalyze = query.substring(("select" + stringSelect[0]+"from" + stringFrom[0] + "where").length(),query.length());
                System.out.println(whereAnalyze.trim());
    
                
            }
                break;
        }
        
            
    }
}